<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head> 
</head>
<title>急报快报配置</title>  
<jsp:include page="/include.jsp"/>

<script type="text/javascript">

   /**
    * 新增急报/快报窗口
    * param reportType 报表类型  1:急报     2:快报
    */
   function doAdd(reportType){
    	var bodyWidth = (reportType == '1')? 1100:800;
	  	window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/urgentrptmgr/speedReportAction!forwardAdd.action?reportType='+reportType,
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-bodyWidth)*0.5,
		    width:bodyWidth,
		    height:560,
			modal:true,
			draggable:false,
			title: (reportType == '1')?'新增急报':'新增快报',
			onClose:function(){
				$('#table_datagrid').datagrid('reload');
				window.top.$(this).dialog('destroy');
			}
	});
   }
   
   /**
   	* 修改急报快报
   	* @param reportId 报表id
   	* @param reportType 报表类型
   	*
   	*/
   function doConfig(reportId, reportType){ 
	   var bodyWidth = (reportType == '1')? 1100:800;
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/urgentrptmgr/speedReportAction!getSpeedReportById.action?reportId='+ reportId + "&reportType="+reportType,
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-bodyWidth)*0.5,
		    width:bodyWidth,
		    height:560,
			modal:true,
			draggable:false,
			title:(reportType == '1')?'修改急报':'修改快报',
			onClose:function(){
				$('#table_datagrid').datagrid('reload');
				window.top.$(this).dialog('destroy');
			}
		});
   }
   
   /**
  	* 急报快报详情
  	* @param reportId 报表id
  	* @param reportType 报表类型
  	*
  	*/
   function doDetail(reportId, reportType){
	   var bodyWidth = (reportType == '1')? 1100:800;
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/urgentrptmgr/speedReportAction!detailSpeedReport.action?reportId='+ reportId + "&reportType="+reportType,
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-bodyWidth)*0.5,
		    width:bodyWidth,
		    height:560,
			modal:true,
			draggable:false,
			title:(reportType == '1')?'急报详情':'快报详情',
			onClose:function(){
				$('#table_datagrid').datagrid('reload');
				window.top.$(this).dialog('destroy');
			}
		});
   }
   
   /**
 	* 急报快报运行结果
 	* @param reportId 报表id
 	* @param reportType 报表类型
 	*
 	*/
  function reportResult(reportId, reportType){
	   var bodyWidth = (reportType == '1')? 1100:800;
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/urgentrptmgr/speedReportAction!forwardReportResult.action?reportId='+ reportId + "&reportType="+reportType,
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-bodyWidth)*0.5,
		    width:bodyWidth,
		    height:560,
			modal:true,
			draggable:false,
			title:(reportType == '1')?'急报运行结果':'快报运行结果',
			onClose:function(){
				$('#table_datagrid').datagrid('reload');
				window.top.$(this).dialog('destroy');
			}
		});
  }
   
   //删除急报快报
   function doDelete(){
	   var p="";
	   var rows=$('#table_datagrid').datagrid('getSelections');
	   if(rows.length==0){
		   window.top.$.messager.alert('提示', '请至少选择一条记录！');
		   return;
	   }else{
		   for(var i in rows){
			   p+=rows[i].reportId+"^";
		   }
		   deleteReportById(p);		      
	   }		
   }
   function deleteReportById(ids){
	   window.top.$.messager.confirm('提示','你是否确定要删除选定的记录？',function(b){
		   if(b){
			   $.ajax({
				   url:'${pageContext.request.contextPath}/urgentrptmgr/speedReportAction!deleteReportById.action',
				   dataType:'json',
				   data:{reportId:ids},
				   success:function(data){
					   $.messager.show({
							title:'提示',
							msg:data.returnMsg
						});
						//刷新主列表
						$('#table_datagrid').datagrid('reload');	
						//移除全选效果
						$(".datagrid-header-check").children("input[type='checkbox']").attr('checked', false);
				   }
			   });
		   }		   
	   });
   }
   
//执行查询
function doQuery(){	
	if ($("#query_form").form("validate"))
	{
		var reportnameQ=$('#reportnameQ').val();	
		var reporttypeQ=$('#reporttypeQ').combobox('getValue');	
		var requiresrcQ=$('#requiresrcQ').combobox('getValue');
		var statusQ=$('#statusQ').combobox('getValue');
		var query={reportnameQ:reportnameQ,reporttypeQ:reporttypeQ,requiresrcQ:requiresrcQ,statusQ:statusQ}; //把查询条件拼接成JSON
		$("#table_datagrid").datagrid('options').queryParams=query; //把查询条件赋值给datagrid内部变量
		$("#table_datagrid").datagrid('load'); //重新加载
	}
}
//重置查询条件
function doReset(){
	$('#query_form').form('reset');
	$('#requiresrcQ').combobox('setValue',null);
	$('#statusQ').combobox('setValue',null);
	$('#reporttypeQ').combobox('setValue',null);
}
   //页面加载完后响应 onReady
$(function(){
	//查询按纽绑定事件
	$('#btnQuery').bind('click',doQuery);
	//重置按纽绑定事件
	$('#btnReset').bind('click',doReset);
	//初始化下拉框
	$('#statusQ').combobox({
		url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getDic.action?dictType=status&&list=list&&tableName=TD_SPEED_REPORT_DEFINE',  
		valueField:'codeValue',
		textField:'codeName',
		required: false,
		editable:false,
		onLoadSuccess:function(){
 	 		$('#statusQ').combobox('setValue',null);
		}
	});
	$('#reporttypeQ').combobox({
		url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getDic.action?dictType=reportType&&list=list',  
		valueField:'codeValue',
		textField:'codeName',
		required: false,
		editable:false,
		onLoadSuccess:function(){
 	 		$('#reporttypeQ').combobox('setValue',null);
		}
	});
	$('#requiresrcQ').combobox({
		url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getDic.action?dictType=requireSrc&&list=list&&excludeValues=4',  
		valueField:'codeValue',
		textField:'codeName',
		required: false,
		editable:false,
		onLoadSuccess:function(){
 	 		$('#requiresrcQ').combobox('setValue',null);
		}
	});

	//初始化主列表
	$('#table_datagrid').datagrid({
		url:'${pageContext.request.contextPath}/urgentrptmgr/speedReportAction!getAllSpeedReportList.action',
		fit:true,
		border:false,
		fitColumns:true,
		pagination:true,
		pageList:[10,20,30],
		rownumbers:false,
		sortName:'createtime',
		sortOrder:'desc',	
		striped:true,
		columns:[[{field:'reportId',title:'选 择',width:50,align:'center',checkbox:true},
		          {field:'reportName',title:'名 称',width:150,align:'left',
					formatter:function(value,rowData,rowIndex){
						return '<div  onmouseover="onMouseOverName(this)"  onmouseout="onMouseOutName(this)" onclick="doDetail(\''+rowData.reportId+'\',\''+rowData.reportType+'\')" style="color:#2b76b7;cursor:pointer;width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.reportName+'">'+rowData.reportName+'</div>';
				  }},
		          {field:'reportType',title:'类 型',hidden:true},
		          {field:'reportTypeName',title:'类 型',width:100,align:'center'},
		          {field:'status',title:'配置状态',hidden:true},
		          {field:'statusName',title:'配置状态',width:100,align:'center'},
		          {field:'requireSrc',title:'需求来源',hidden:true},
		          {field:'requireSrcName',title:'需求来源',width:150,align:'center'},
		          {field:'creator',title:'创建者',width:100,align:'center'},
		          {field:'createTime',title:'创建时间',width:140,align:'center'},
		          {field:'action',title:'操 作',width:230,align:'left',
		        	  formatter:function (value,row,index){
						var str='<span  style="cursor:pointer" onclick="doConfig(\''+row.reportId+'\', \''+row.reportType+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改" style="margin-top:2px;"/>修改&nbsp;&nbsp;</span>';
						str += '<span style="cursor:pointer" onclick="deleteReportById(\''+row.reportId+'\')"><img src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;">删除&nbsp;&nbsp;</span>';
						if (row.status == 1)
						{
							str += '<span  style="cursor:pointer" onclick="kpiSubscribleMgrTabs(\''+row.reportId+'\',\''+row.reportName+'\',\''+row.reportType+'\',\''+row.reportTypeName+'\')"><img  src="${pageContext.request.contextPath}/images/icons/subscription.png" title="订阅" alt="订阅" style="margin-top:2px;"/>订阅&nbsp;&nbsp;</span>';
							str += '<span  style="cursor:pointer" onclick="reportResult(\''+row.reportId+'\',\''+row.reportType+'\')"><img  src="${pageContext.request.contextPath}/images/icons/subscription.png" title="运行结果" alt="运行结果" style="margin-top:2px;"/>运行结果&nbsp;&nbsp;</span>';
						}
		        	  	return str;
		        	  }
				  }
		        ]],
		toolbar:'#table_datagrid_toobar'
	});
});
/**跳转到指标订阅页面:管理员页面和普通用户页面
 *reportid:急报Id
 *reportname：急报名称
 *reporttype：资源类型
 *reporttypename：资源类型名称
 */
function kpiSubscribleMgrTabs(reportid,reportname,reporttype,reporttypename){
	 var pars="userId="+$("#dqm_speedreport_userId").val();
	     pars+="&userName="+$("#dqm_speedreport_userName").val();
	     pars+="&resourceId="+reportid;
	     pars+="&subscribleName="+reportname;
	     pars+="&resourceType="+reporttype;
	     pars+="&resourceTypeName="+reporttypename;
		if($("#dqm_speedreport_userId").val().toUpperCase()=="ADMIN"){//管理员页面
			 window.top.$('<div/>').dialog({
	    		  href:'${pageContext.request.contextPath}/basemgr/kpiSubscribleAction!kpiSubscribleMgrTabs.action?'+pars,
	    		  width : 650,
	 			  height : 400,
	 			  modal : true,
	 			  cache: false,   
	 			  title : reporttypename+'订阅',
	 			  onClose : function() {
	 				  window.top.$(this).dialog('destroy');
	 			  }

	 		 });
		 }else{//普通用户
			 window.top.$('<div/>').dialog({
				    href:'${pageContext.request.contextPath}/basemgr/kpiSubscribleAction!kpiSubscribleMgrTabs.action?'+pars,
				    width : 460,
					height :285,
					modal : true,
					cache: false,   
					title : reporttypename+'订阅',
				    onClose : function() {
	 				     window.top.$(this).dialog('destroy');
	 			    }
			});
		}
 	 
 }
</script>
<body class="easyui-layout">
   <div id="dqm_speedreport_divId" ></div>
	<input type="hidden" id="dqm_speedreport_userId" name="userId" value="${sessionInfo.userid}"> <!-- 用户Id -->
	<input type="hidden" id="dqm_speedreport_userName" name="userName" value="${sessionInfo.username}"> <!-- 用户名称 -->
	<form id="query_form" method="post">
	    <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
	    	<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
	    		<tr>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			   <label for="reportnameQ">名称：</label>
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    				<input type="text" id="reportnameQ" name="reportnameQ" class="easyui-validatebox" data-options="validType:'specialCharFilter'" />
	    			</td>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			   <label for="reporttypeQ">类型：</label>
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">	    				
	    				<input id="reporttypeQ" type="text" class="easyui-combobox" name="reporttypeQ" panelHeight="auto"/>
	    			</td>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			  <label for="requiresrcQ">需求来源：</label>
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">	    				
	    				<input id="requiresrcQ" type="text" class="easyui-combobox" name="requiresrcQ" panelHeight="auto"/>
	    			</td>	    		
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			   <label for="statusQ">配置状态：</label>
	    			</td>
	    			<td style="text-align:left;width:15%;padding-right:55px" nowrap="nowrap">	    				
	    				<input id="statusQ" type="text" class="easyui-combobox" name="statusQ" panelHeight="auto""/>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    			</td>    		
	    			<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
						<input type="button" id="btnQuery" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>	
			    		<input type="button" id="btnReset" value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:55px"/>		
	    			</td>
	    		</tr>	    			    						    	    		
	    	</table>	    	
	    </div>  
	    <div data-options="region:'center'" style="border-top:none">
			<table id="table_datagrid"></table>
			<div id="table_datagrid_toobar" class="etl_panel_title" >
				<a href="javascript:void(0);" onclick="doAdd(1)" class="easyui-linkbutton" data-options="iconCls:'icon-sum',plain:true" style="float:left;">新增急报</a>
				<div class="datagrid-btn-separator"></div>
				<a href="javascript:void(0);" onclick="doAdd(2)" class="easyui-linkbutton" data-options="iconCls:'icon-tip',plain:true" style="float:left;">新增快报</a>
				<div class="datagrid-btn-separator"></div>
				<a href="javascript:void(0);" onclick="doDelete()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">批量删除</a>
			</div>
		</div>
    </form>
</body>  
</html>

